// /////////////////////////////////////////////////////////////////////////////
//
// Name:            asScript.cpp
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Binds the Script class to AngelScript
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

// Include files
#include "asScript.h"

#ifdef __COMPILE_WITH_ANGELSCRIPT__

#include "../ScriptHelper.h"

#include "../Script.h"


//! Reference factory for the Script class.
Script* createScript(const std::string &name)
{
    return new Script(name);
}

//! Binds the Script class to AngelScript.
void bindScript(asIScriptEngine *engine)
{
    // Forward declarations.
    int r;

    // Bind DataStack class.
    r = engine->RegisterObjectType("Script", sizeof(Script), asOBJ_REF); assert(r >= 0);

    // Set DataStack behaviour.
    r = engine->RegisterObjectBehaviour("Script", asBEHAVE_FACTORY, "Script@ f(const string &in)",
                                        asFUNCTION(createScript), asCALL_CDECL); assert(r >= 0);
    r = engine->RegisterObjectBehaviour("Script", asBEHAVE_ADDREF, "void f()",
                                        asMETHOD(Script, grab), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectBehaviour("Script", asBEHAVE_RELEASE, "void f()",
                                        asMETHOD(Script, drop), asCALL_THISCALL); assert(r >= 0);

   // Bind DataStack class functions.
    r = engine->RegisterObjectMethod("Script", "u32 getID()",
                                     asMETHOD(Script, getID), asCALL_THISCALL); (r >= 0);
    r = engine->RegisterObjectMethod("Script", "const string& getName()",
                                     asMETHOD(Script, getName), asCALL_THISCALL); assert(r >= 0);

    r = engine->RegisterObjectMethod("Script", "bool loadScript(const string &in)",
                                     asMETHODPR(Script, loadScript, (const std::string&), bool),
                                     asCALL_THISCALL);assert(r >= 0);
    r = engine->RegisterObjectMethod("Script", "bool unloadScript()",
                                     asMETHOD(Script, unloadScript), asCALL_THISCALL);assert(r >= 0);

    r = engine->RegisterObjectMethod("Script", "bool executeFunctionByName(const string &in, const string &in)",
                                     asMETHOD(Script, executeFunctionByName), asCALL_THISCALL);assert(r >= 0);
}

#endif // __COMPILE_WITH_ANGELSCRIPT__

// End of File
